<?php 
/********* Dreamscape ***********/
class outputMessages {

function outputMessages(){}

function printOut($message, $more=""){
global $output, $report;

	if(is_array($message)){
		foreach($report as $level => $reports){
			$report[$level] = array_unique($report[$level]);
		}
		foreach($report['error'] as $val){
			$output .= '<p class="contenterror">'.$val.'</p>';
		}
		foreach($report['success'] as $val){
			$output .= '<p class="contentsuccess">'.$val.'</p>';
		}
		foreach($report['alert'] as $val){
			$output .= '<p class="contentalert">'.$val.'</p>';
		}

	} else {
		if(empty($more)){
		$output .= $message;
		} elseif(is_array($more)) {
		$output .= vsprintf($message, $more);
		} else {
		$output .= sprintf($message, $more);
		}
	}
}
/**
 * Writes the header
 * @param string $pagetitle
 * @param int $is_vanilla
 * @param int $is_install
 * @return void
 */
function write_header ($pagetitle, $is_vanilla=0, $is_install=0) 
{
global $auth, $xajax, $sections, $items, $module_css, $module_js, $page_meta, $headerDate; 
$finaltitle = CMS_NAME.L_MENU_SEPARATOR.CMS_VERSION.' ';
add_title($finaltitle, 1);
$default = L_DEFAULT_TITLE;
$type = check_get_alphanum('type');
	if(!$is_install){
		switch (true) {
		case ADDING:
		case EDITING:
		   break;
		 case CAT == 'admin':
		 add_title(L_MENU_ADMIN_SETTINGS, 2);
		 break;
		 case !ADDING && !EDITING && CAT != 'admin' && empty($type) && LOGGED_IN:
		 add_title(sprintf(L_MAIN_TITLE,CMS_NAME), 2);
		 break;
		 case !LOGGED_IN:
		 add_title(sprintf(L_LOGIN_TITLE,CMS_NAME), 2);
		 break;
		default:
			add_title($default, 2);
		break;
		}
	}
if ($is_vanilla && $is_install){
		reset_title();
		add_title($finaltitle, 1);
		add_title('installing dreamscape :: the cms for creative people.', 2);
		}
$finaltitle = make_title();
$finaltitle = applyOzone('admin_title',$finaltitle);
$main_css = 'css/dreamscape.css.php'.($is_install ? '?extend=install': '');
$main_js = 'javascript/dreamscape.js.php'.(isset($_GET['cat_id']) ? '?full=true' : '');
$main_css = applyOzoneAction('admin_css_url', $main_css);
$main_js = applyOzoneAction('admin_js_url', $main_js);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $finaltitle;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="copyright" content="Ryan Miglavs" />
<meta name="language" content="EN-US" />
<meta name="rating" content="General" />
<meta name="robots" content="index,follow" />
<meta name="revisit-after" content="7" />
<meta name="distribution" content="global" />
<meta name="author" content="Nate Cavanaugh, Jason Morrison, Ryan Miglavs" />
<link rel="shortcut icon" href="favicon.ico" />
<link href="<?php echo $main_css ?>" rel="stylesheet" type="text/css" />
<?php echo (!empty($module_css)) ? '<link href="'.$module_css.'" rel="stylesheet" type="text/css" />' : ''; ?>
<script language="JavaScript" type="text/javascript">
/*For users with Javascript*/
document.write('<link href="css/dreamscape.js.css" rel="stylesheet" type="text/css" />');
</script>
<script type="text/javascript" src="funcs/FCKeditor/fckeditor.js"></script>
<script type="text/javascript" src="javascript/control.textarea.js"></script>
<?php echo (!empty($module_js)) ? '<script type="text/javascript" src="'.$module_js.'"></script>' : ''; ?>
<script type="text/javascript" src="<?php echo $main_js ?>"></script>
<?php if(isset($xajax) && is_object($xajax)){
$xajax->printJavascript("./funcs/");
}
$company_logo = COMPANY_LOGO;
if(!empty($company_logo) && CUSTOM_INSTALL){
?>
<style>
#header h1 a, #header h1 a:hover{
background: url(<?php echo $company_logo; ?>) no-repeat;
}
</style>
<?php }
applyOzoneAction('admin_header');
 ?>
</head>
<body <?php if($is_vanilla){ ?>id="vanilla"<?php } ?>> 
<?php 
if(!$is_install){
	if(PENDING_UPDATE && CAT != 'upgrade' && LOGGED_IN){
	echo '<div id="upgradeOverlay"></div>';
	echo '<div id="upgradeInstructions">'.sprintf(L_UPGRADE_INSTRUCTIONS,CMS_NAME, CMS_VERSION).'</div>';
	}
}
?>
<div id="mainContainer">
<!-- Begin Header --> 
<div id="header"><h1><a href="./"><span><?php echo CMS_NAME ?></span></a></h1>
<p><?php
if(!$is_install){
?><?php printf(L_WELCOME, HEADER_ID);?><?php 
if($auth->Admin){ ?><?php echo L_MENU_SEPARATOR ?><a href="index.php?cat=admin"><?php echo L_MENU_ADMIN_SETTINGS ?></a><?php } ?><?php echo L_MENU_SEPARATOR ?><a href="<?php echo YOUR_SITE.INDEX_PAGE; ?>" target="_blank"><?php echo L_MENU_VIEW_SITE ?></a>
<?php echo (LOGGED_IN == true) 
		? L_MENU_SEPARATOR.'<a href="index.php?action=logout" id="logoutLink">'.L_LOGOUT.'</a>' 
		: ''; ?>
<?php 
} else {
$install_step = check_get_alphanum('step');
$uninstall_type = check_get_alphanum('uninstall_type');
if($install_step == 'install'){
$step ='Installing '.CMS_NAME;
} elseif($install_step == 'uninstall') {
$step = 'Uninstalling '.CMS_NAME;
$step .= ($uninstall_type == 'manual') ? ': Manually' : '';
} else {
$step = CMS_NAME.' wants to know what you\'re doing';
}
?>
 <?php echo $step ?>
<?php
}
 ?><br />
<?php echo isset($headerDate) ? $headerDate : ''; ?></p></div>
<!-- End Header --> 
<?php

}

/**
 * Creates the breadcrumbs HTML
 * @param string $section
 * @param $type
 * @return void
 */
function generateBreadCrumbs($section, $type){
global $Database, $admin_menu;
$item_id = ITEM_ID;
$separator = L_SEPARATOR;
$sections = get_dao('sections');
$sections->Get($section);
$section = $sections->sectionname;
$category_header = $section;


add_breadcrumb('<a href="./">'.L_CRUMB_HOME.'</a>', 1);
if(ADDING){
add_breadcrumb(sprintf(L_CRUMB_ADD,ucwords($section)), 2);
} elseif(EDITING){
	if(!empty($section)){
		if(EDIT_LIST){
		add_breadcrumb(sprintf(L_CRUMB_EDIT,ucwords($section)), 2);
		} else{
		global $the_module;
		$items = $the_module->items;
		$title = !empty($items->title) ? $items->title : L_NO_TEXT_IN_TITLE;
		add_breadcrumb('<a href="index.php?type=edit&amp;cat_id='.$sections->id.'">'.sprintf(L_CRUMB_EDIT,ucwords($section)).'</a>', 2);
		add_breadcrumb(sprintf(L_CURRENTLY_EDITING_HTML,$title), 3);
		}
	}
} elseif(CAT == 'admin') {
	 $category_header = L_MENU_ADMIN_SETTINGS;
	 $admin_sub = ADMIN_SUB;
	 if(empty($admin_sub)){
	 add_breadcrumb(L_CRUMB_EDIT_ADMIN, 2);
	 } else{
	 add_breadcrumb('<a href="index.php?cat=admin">'.L_CRUMB_EDIT_ADMIN.'</a>', 2);
	 }
	} elseif(CAT == 'upgrade'){
	$category_header = L_UPDATE_TITLE;
	add_breadcrumb(sprintf(L_UPDATE_CRUMB,CMS_NAME), 2);
	}

$category_header = applyOzoneAction('category_header', $category_header);

$breadcrumbs = make_breadcrumbs();
?>
<h1><?php echo $category_header;  ?></h1>
<h2><?php echo $breadcrumbs  ?></h2>
<?php
}


/**
 * Writes a footer
 * @return void
 */
function write_footer() 
{
global $auth;
$is_admin = (isset($auth) && is_object($auth) && $auth->Admin == true);
$upgradable = (defined('UPGRADE_AVAILABLE') && UPGRADE_AVAILABLE == true);
$show_label = (isset($_SESSION['username']) && $upgradable && $is_admin);
?>
<!-- Begin Footer --> 
<div id="footer"><p><a href="<?php echo COMPANY_URL ?>" target="_blank"><?php echo COMPANY_NAME ?></a>. <?php printf(L_COPYRIGHT_FOOTER, date('Y'));?><?php if(!CUSTOM_INSTALL){ ?><?php echo L_MENU_SEPARATOR ?><a href="misc.php?action=license"><?php echo L_LEGAL_FOOTER ?></a><?php echo L_MENU_SEPARATOR ?><a href="http://forums.dreamscapecms.com" target="_blank"><?php echo L_SUPPORT_FOOTER ?></a><?php } ?></p>
</div>
<!-- End Footer --> 
</div>
<?php if($show_label){ ?>
<p id="upgrade"><a href="http://dreamscapecms.com/download/" target="_blank"><?php printf(L_UPGRADE_AVAILABLE, UPGRADE_VERSION); ?></a></p>
<?php } 
global $LEX_JS;
echo is_array($LEX_JS) ? implode("\n",$LEX_JS) : '';
applyOzoneAction('admin_footer');
?>
</body>
</html>
<?php
}

}
?>
